﻿using AutoMapper;
using B.S.DataBase.MyProject.Domain.wdx;
using B.S.DataBase.MyProject.ErrorCode;
using B.S.DataBase.MyProject.Infrastructure;
using MediatR;
using MedicalPCTerminal.Write.API.Appcation.Commands.Sign;

namespace MedicalPCTerminal.Write.API.Appcation.CommandHandlers.Sign
{
    public class AddSignDeviceBindCommandHandler:IRequestHandler<AddSignDeviceBindCommand, APIResult<object>>
    {
        private readonly SqlSugarContext sqlSugar;
        private readonly IMapper mapper;

        public AddSignDeviceBindCommandHandler(SqlSugarContext sqlSugar, IMapper mapper)
        {
            this.sqlSugar = sqlSugar;
            this.mapper = mapper;
        }

        public Task<APIResult<object>> Handle(AddSignDeviceBindCommand request, CancellationToken cancellationToken)
        {
            APIResult<object> result = new APIResult<object>();
            //var model = mapper.Map<SignDeviceBind>(request);
            //var r = sqlSugar.db.Insertable(model).ExecuteCommand();
            var r = sqlSugar.db.Insertable(request.signDeviceBinds).ExecuteCommand();
            if (r > 0)
            {
                result.Code = APIEnum.添加成功;
                result.Msg = APIEnum.添加成功.ToString();
            }
            else
            {
                result.Code = APIEnum.添加失败;
                result.Msg = APIEnum.添加失败.ToString();
            }
            return Task.FromResult(result);
        }
    }
}
